﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace _7._18
{
    class Program
    {
        public static int[] Mus()
        {
            int[] arr1 = new int[4];
            for (int i = 0; i < 4; ++i)
            {
                Console.Write("a[{0}]=", i);
                arr1[i] = int.Parse(Console.ReadLine());
            }
            return arr1;
        }
        public static int[] Mus2()
        {
            int[] arr2 = new int[4];
            for (int i = 0; i < 4; ++i)
            {
                Console.Write("a[{0}]=", i);
                arr2[i] = int.Parse(Console.ReadLine());
            }
            return arr2;
        }

        public static ArrayList Set1(int[] arr1, int[] arr2)
        {
            ArrayList arr3 = new ArrayList();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (arr1[i] == arr2[j])
                    {
                        arr3.Add(arr1[i]);
                    }
                }
            }
            return arr3;
        }
        public static void Set2(ArrayList arr3)
        {
            foreach (int s in arr3) 
            Console.Write(s + " ");
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Вводим первый массив");
            int[] arr1 = Mus();
            Console.WriteLine("Вводим второй массив");
            int[] arr2 = Mus2();
            ArrayList arr3 ;
            arr3 = Set1(arr1,arr2);
            Set2(arr3);
        }
    }
}